﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="房产销冠, 房地产,卡考网络" />
    <meta name="description" content="上海卡考网络有限公司" />
    <title>房产销冠</title>
    <link rel="stylesheet" href="css/global.css" type="text/css" />
    <link rel="stylesheet" href="css/form.css" type="text/css" />
    <link rel="stylesheet" href="css/default.css" />
    <link href="bootstrap/iCheck-master/skins/minimal/orange.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="css/gri.controls.css" type="text/css" />
    <link rel="stylesheet" href="css/bootstrap-switch.css" type="text/css" />
    <script src="http://dn-blqw.qbox.me/jq+bs+art.js" type="text/javascript"></script>
    <script src="js/jquery-form.js" type="text/javascript"></script>
    <script src="js/underscore.js" type="text/javascript"></script>
    <script src="js/jquery-my-Extension.js" type="text/javascript"></script>
    <script src="js/kk.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/WdatePicker.js"></script>
    <!--<script type="text/javascript" src="js/dateRange.js"></script>-->
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/formValidator.js"></script>
    <!--图片上传-->
    <link href="Scripts/webuploader/webuploader.css" rel="stylesheet" />
    <script type="text/javascript" src="bootstrap/iCheck-master/icheck.js"></script>
    <script type="text/javascript" src="js/bootstrap-switch.min.js"></script>
    <script src="Scripts/webuploader/webuploader.min.js" type="text/javascript"></script>
    <script src="Scripts/webuploader/webupload.expand.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //单图上传
            $("#btnUpLoadL").powerWebUpload({
                onComplete: function (data) {
                    //alert(JSON.stringify(data));
                    if (data.state == 0) {
                        $kk.popup(data.filePath, "err", 2000);
                    } else {
                        $('#imgBuilding').attr('src', data.filePath);
                        $("#picUrl").val(data.filePath);
                    }
                },
                PostbackHold: false
            });
            var imgUrl = $("#picUrl2").val();
            $("#btnUpLoadL2").powerWebUpload({
                onComplete: function (data) {
                    //alert(JSON.stringify(data));
                    if (data.state == 0) {
                        $kk.popup(data.filePath, "err", 2000);
                    } else {
                        $('#imgBuilding2').attr('src', data.filePath);
                        $("#picUrl2").val(data.filePath);
                        imgUrl = data.filePath;
                    }
                },
                PostbackHold: false
            });

            //多图上传
            //var imgUrl = $("#productPic").val();
            //$("#btnUpLoadList").powerWebUpload({
            //    onComplete: function (data) {
            //        if (data.state == 0) {
            //            $kk.popup(data.filePath, "err", 2000);
            //        } else {
            //            //var str = "<div class='frompic2 fl'><div><img src='http://" + window.location.host + data.filePath + "'  width='200' height='150'  /></div><div class='picdetline2'><img src='images/from_picclose.png' />删除</div>";
            //            var str = "<div class='frompic2 fl'><div><img src='" + data.filePath + "'  width='200' height='150'  /></div><div class='picdetline2'><img src='images/from_picclose.png' />删除</div>";
            //            $("#imgListShow").append(str);
            //            if (imgUrl != "" || imgUrl != null) {
            //                imgUrl += "|";
            //            }
            //            imgUrl += data.filePath;
            //            $("#productPic").val(imgUrl);
            //        }
            //    },
            //    PostbackHold: true,
            //    ShowDownload: true
            //});

        });

    </script>
    <!--<script charset="utf-8" src="js/kindeditor-min.js"></script>-->
    <!--<script charset="utf-8" src="js/zh_CN.js"></script>-->
    <script type="text/javascript">
        $(document).ready(function () {
            initInput();
        });
        function initInput() {
            $('.lab112 :checkbox').iCheck({
                checkboxClass: 'icheckbox_minimal-orange',
                radioClass: 'iradio_minimal-orange',
                increaseArea: '20%' // optional
            });
            $('.lab112 :radio').iCheck({
                checkboxClass: 'icheckbox_minimal-orange',
                radioClass: 'iradio_minimal-orange',
                increaseArea: '20%' // optional
            });
        }


    </script>
</head>
<body style="background: #f1f1f1;">
    <div class="main01 pb50">
        <div class="fromtit1 clearfix">
            <h1 class="ff">商品管理》<span id="EditTitle" style="font-size:16px;font-weight:300;">添加商品</span></h1>
            <a href="#" class="gouback" onclick="f_Back();">返回</a>
        </div>
        <div class="fromtit2 clearfix">
            <h2 class="ff">展示信息</h2>
        </div>
        <div class="frommod clearfix">
            <form id="form1">
                <input type="hidden" id="kid" name="kid" value="0" />
                <input type="hidden" id="ruleKid" name="ruleKid" value="0" />
                <table border="0" cellspacing="0" cellpadding="0" class="fromtab1">
                    <tr>
                        <th>商品分类：&nbsp;</th>
                        <td>
                            <select id="F_CateogryKid" class="selall sel100 fl" style="margin-right: 11px;">
                                <option>--商品分类--</option>
                            </select>
                            <input type="hidden" id="categoryKid" name="categoryKid" value="0" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品名称：&nbsp;</th>
                        <td>
                            <input type="text" id="productName" name="productName" value="" class="inpall inp435" placeholder="请填写商品标题" maxlength="16" validatetype="*notempty" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品编号：&nbsp;</th>
                        <td>
                            <input type="text" id="code" name="code" value="999" class="inpall inp435" placeholder="请填写商品编码" maxlength="25" validatetype="*notempty" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品介绍：&nbsp;</th>
                        <td>
                            <textarea id="description" name="description" rows="" cols="" class="textall02 text435" placeholder="请输入详细说明" validatetype="notempty"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>商品缩略图：&nbsp;</th>
                        <td>
                            <div class="clearfix">
                                <div class="frompic1 fl" id="">
                                    <div>
                                        <img id="imgBuilding" src="images/build_pics.jpg" width="105" height="77" alt="" />
                                    </div>
                                    <div class="picdetline" onclick="DeleteFileByUrl()">
                                        <img src="images/from_picclose.png" alt="" />
                                        删除
                                    </div>
                                </div>
                                <div class="fl">
                                    <div class="picinfos" id="btnUpLoadL">(请上传图片 )</div>
                                    <input type="hidden" id="picUrl" name="picUrl" value="" />
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>商品详情图：&nbsp;</th>
                        <td>
                            <div class="clearfix">
                                <div class="frompic2 fl" id="imgListShow">
                                    <div>
                                        <img id="imgBuilding2" src="images/build_pics.jpg" width="105" height="77" alt="" />
                                    </div>
                                    <div class="picdetline" onclick="DeleteFileByUrl2()">
                                        <img src="images/from_picclose.png" alt="" />
                                        删除
                                    </div>
                                </div>
                                <div class="fl">
                                    <div class="picinfos" id="btnUpLoadL2">(请上传图片 )</div>
                                    <input type="hidden" id="picUrl2" name="productPic" value="" />
                                </div>
                            </div>
                        </td>
                    </tr>
                    <!--  <tr>
                        <th>商品详情图：&nbsp;</th>
                        <td>
                            <div class="clearfix">
                                <div class="frompic2 fl" id="imgListShow">
                                                                      <div>
                                                                            <img id="img1" src="images/build_pics.jpg" width="105" height="77" alt="" />
                                                                        </div>
                                                                        <div class="picdetline">
                                                                            <img src="images/from_picclose.png" alt="" />
                                                                            删除
                                                                        </div>
                                </div>
                                <div class="fl">
                                    <div class="picinfos" id="btnUpLoadList">(请上传图片 )</div>
                                    <input type="hidden" id="productPic" name="productPic" value="" />
                                </div>
                            </div>
                        </td>
                    </tr>-->
                    <tr>
                        <th>需要积分：&nbsp;</th>
                        <td>
                            <input type="text" id="pointNum" name="pointNum" value="" class="inpall inp435" placeholder="请输入消耗积分" validatetype="*number" onkeyup="clearNoPhone_Number(this)" maxlength="10" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品单价：&nbsp;</th>
                        <td>
                            <input type="text" id="productPrice" name="productPrice" value="" class="inpall inp435" placeholder="请输入商品实际价格" validatetype="*arithmetic" maxlength="10" onkeyup="IsDouble(this)"/>
                        </td>
                    </tr>
                    <tr>
                        <th>上架数量：&nbsp;</th>
                        <td>
                            <input type="text" id="stockNum" name="stockNum" value="" class="inpall inp435" placeholder="请输入上架数" validatetype="*number" onkeyup="clearNoPhone_Number(this)" maxlength="10" />
                        </td>
                    </tr>
                    <tr>
                        <th>库存剩余：&nbsp;</th>
                        <td>
                            <input type="text" id="inventoryNum" name="inventoryNum" value="" class="inpall inp435" placeholder="请输入库存数" validatetype="*number" onkeyup="clearNoPhone_Number(this)" maxlength="10" />
                        </td>
                    </tr>
                    <tr>
                        <th>兑换时期：&nbsp;</th>
                        <td>
                            <!--<div class="date" id="div_date">
                                <span class="date_title" id="date">2014-12-16 至 2014-12-22</span>
                                <input type="hidden" id="beginTime" name="beginTime" value="2014-12-16" />
                                <input type="hidden" id="endTime" name="endTime" value="2014-12-22" />
                                <a class="opt_sel" id="input_trigger" href="#">
                                    <i class="i_orderd"></i>
                                </a>
                            </div>-->
                            <input type="text" id="beginTime" name="beginTime" class="inpall" value="" onclick="WdatePicker()" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd',minDate: '%y-%M-%d' })" placeholder="请选择时间" />
                            -至-&nbsp;<input type="text" id="endTime" name="endTime" class="inpall" value="" onclick="WdatePicker()" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'beginTime\')}' })" placeholder="请选择时间" />
                        </td>
                    </tr>
                    <tr>
                        <th>每个用户兑换次数：&nbsp;</th>
                        <td>
                            <input type="text" id="userExchangeNum" name="userExchangeNum" value="" class="inpall inp329 fl" placeholder="请填写兑换次数" validatetype="*number" validateoffset="0,105" onkeyup="clearNoPhone_Number(this)" maxlength="10" />
                            <div class="fromsex fl">
                                <a href="#" class="sex_1 on" onclick="SexSelect1()">永久</a><a href="#" class="sex_2" onclick="SexSelect2()">每天</a>
                                <input type="hidden" id="exchangeType" name="exchangeType" value="0" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td>
                            <label class="lab112">
                                <input type="radio" name="isSelect" value="0" />&nbsp;&nbsp;自动处理
                            </label>
                            <label class="lab112">
                                <input type="radio" name="isSelect" value="1" />&nbsp;&nbsp;手动处理
                            </label>
                            <input type="hidden" id="status" name="status" value="0" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品来源：&nbsp;</th>
                        <td>
                            <input type="text" id="source" name="source" value="" class="inpall inp435" placeholder="请填写商品来源" maxlength="200" />
                        </td>
                    </tr>
                    <tr>
                        <th>排序：&nbsp;</th>
                        <td>
                            <input type="text" id="sort" name="sort" value="" class="inpall inp100" placeholder="排序" validatetype="*number" onkeyup="clearNoPhone_Number(this)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <th>开启兑换限制：&nbsp;</th>
                        <td style="width: 120px;">
                            <div class="make-switch" id="F_IsExchange" data-switch-get="state" data-on-label="开启" data-off-label="关闭">
                                <input type="checkbox" name="F_IsExchange" class="isExchange" />
                                <input type="hidden" id="isExchange" value="0" name="isExchange" />
                            </div>
                        </td>
                    </tr>
                    <tr style="display:none;">
                        <th>每日限兑数量：&nbsp;</th>
                        <td>
                            <input type="text" id="exchangeNum" name="exchangeNum" value="0" class="inpall inp435" placeholder="请输入每日限制兑换数量" onkeyup="clearNoPhone_Number(this)" maxlength="10" />
                        </td>
                    </tr>
                    <tr style="display:none;">
                        <th>每日限兑时间：&nbsp;</th>
                        <td>
                            <input type="text" id="beginHour" class="inpall inp80 fl" maxlength="2" value="08" placeholder="08" onkeyup="clearNoPhone_Number(this)" />
                            <span class="inpword fl">时</span>
                            <input type="text" id="beginMinute" class="inpall inp80 fl" maxlength="2" value="00" placeholder="00" onkeyup="clearNoPhone_Number(this)" />
                            <span class="inpword fl">分</span>
                            <input type="hidden" id="exchangeBeginTime" name="exchangeBeginTime" />
                            <div class="fl">至</div>
                            <input type="text" id="endHour" class="inpall inp80 fl" maxlength="2" value="17" placeholder="17" onkeyup="clearNoPhone_Number(this)" />
                            <span class="inpword fl">时</span>
                            <input type="text" id="endMinute" class="inpall inp80 fl" maxlength="2" value="00" placeholder="00" onkeyup="clearNoPhone_Number(this)" />
                            <span class="inpword fl">分</span>
                            <input type="hidden" id="exchangeEndTime" name="exchangeEndTime" />
                        </td>
                    </tr>
                    <tr style="display:none;">
                        <th>是否参与秒杀：&nbsp;</th>
                        <td style="width: 120px;">
                            <div class="make-switch" id="F_IsMeskill" data-switch-get="state" data-on-label="参与" data-off-label="不参与">
                                <input type="checkbox" name="F_IsMeskill" class="isMeskill" />
                                <input type="hidden" id="isMeskill" value="0" name="isMeskill" />
                            </div>
                        </td>
                    </tr>
                    <tr style="display:none;">
                        <th>所属城市：&nbsp;</th>
                        <td>
                            <select id="F_CityKid" class="selall sel260" style="margin-right:11px;">
                                <option value="">所有城市</option>
                            </select>
                            <input type="hidden" value="" id="ruleToCity" name="ruleToCity" />
                        </td>
                    </tr>
                    <!--<tr>
                        <th>使用地域：&nbsp;</th>
                        <td class="addarea">
                            <div class="fl">
                                <ul class="new_city"></ul>
                            </div>
                            <div class="add_city fl" style="margin-left: 8px; margin-top: 9px; font-weight: bold; height: 14px; width: 14px; line-height: 12px; border: 1px solid #0074d9; color: #0074d9; border-radius: 50%;cursor:pointer;">
                                +
                            </div>

                        </td>
                    </tr>-->
                    <tr>
                        <th>&nbsp;</th>
                        <td>
                            <div class="sinput">
                                <input type="button" class="Save" value="加入仓库" onclick="f_AddWarehouse()" />
                                <input type="button" class="Cancel" value="立即上架" onclick="f_ImmediatelyOn()" />
                            </div>
                        </td>
                    </tr>

                </table>
                <!--<div class="appear_city">
                    <ul class="appear_city_nav">
                        <li value="112">杭州市</li>
                        <li value="115">宁波市</li>
                        <li value="331">西安市</li>
                        <li value="259">成都市</li>
                        <li value="184">洛阳市</li>
                        <li value="37">上海市</li>
                        <li value="38">重庆市</li>
                        <li value="129">黄山市</li>
                        <li value="159">济南市</li>
                        <li value="172">日照市</li>
                        <li value="193">武汉市</li>
                        <li value="234">深圳市</li>
                        <li value="97">南京市</li>
                    </ul>
                    <div class="sinput">
                        <input type="button" class="btnCancel" value="取消" onclick="btnCan()" /><input type="button" class="btnSave" value="确认" onclick="btnSav()" />
                    </div>
                    <input type="hidden" value="" id="ruleToCity" name="ruleToCity" />
                </div>-->
            </form>
        </div>
    </div>

    <script type="text/javascript">

        $("#F_CityKid").change(function () {
            $("#ruleToCity").val($(this).val());
        });
        $("input[name='isSelect']:eq(0)").on('ifChecked', function (event) {
            $("#source").parents("tr").show();
            $(this).attr("validatetype", "*notempty");
            $("#status").val("0");
        });
        $("input[name='isSelect']:eq(1)").on('ifChecked', function (event) {
            $("#source").parents("tr").hide();
            $("#status").val("1");
            $("#source").val("");
        });
        //var myDate = new Date();
        //var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        //var month = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
        //var date = myDate.getDate(); //获取当前日(1-31)
        //tomo = new Date((myDate / 1000 + 86400 * 30) * 1000);//先加上15天
        //var year2 = tomo.getFullYear(); //获取完整的年份(4位,1970-????)
        //var month2 = tomo.getMonth(); //获取当前月份(0-11,0代表1月)
        //var date2 = tomo.getDate(); //获取当前日(1-31)
        //var time = year + "-" + (month + 1) + "-" + date;
        //var tomo = year2 + "-" + (month2 + 1) + "-" + date2;
        //var dateRange = new pickerDateRange('date', {
        //    startDate: "2015-1-13", // startDate 开始时间
        //    endDate: "2015-1-30", // endDate 结束时间
        //    theme: 'ta',
        //    target: 'asdfasdf', // target 日期选择框摆放的位置, 一般是在 form 中
        //    success: function (obj) {
        //        //alert($("#date").val());
        //        var selectDate = $("#date").val();
        //        $("#beginTime").val(selectDate.split(' 至 ')[0]);
        //        $("#endTime").val(selectDate.split(' 至 ')[1]);
        //    }
        //});

        //地域选择
        $(".add_city").click(function () {
            $(".appear_city").fadeIn();
            $(".appear_city_nav li").removeClass("addbg");
            $(".new_city").find("li[class='addbg']").each(function () {
                var liobj = $(this);
                $(".appear_city_nav").find("li").each(function () {
                    if ($(this).html() == liobj.html()) {
                        $(this).addClass("addbg");
                    }
                });
            });
        });

        $(".appear_city_nav li").click(function () {
            $(this).toggleClass("addbg");
        });
        function btnCan() {
            $(".appear_city").fadeOut();
        }


        //=============================数组扩展方法 begin======================================

        Array.prototype.baoremove = function (dx) {
            if (isNaN(dx) || dx > this.length) { return false; }
            this.splice(dx, 1);
        }

        //=============================数组扩展方法 end========================================

        function btnSav() {
            $(".new_city").html("");
            $(".appear_city_nav").find("li[class='addbg']").each(function () {
                var liobj = $(this);
                var iscunzai = false;

                $(".new_city").find("li").each(function () {
                    if (!iscunzai) {
                        if ($(this).html() == liobj.html()) {
                            iscunzai = true;
                        }
                    }
                });
                if (!iscunzai) {
                    $(".new_city").append($(this).clone());
                }
            });
            $('.new_city li').mouseover(function () {
                $(this).removeClass("addbg").addClass("delbg");
            });
            $(".new_city li").mouseout(function () {
                $(this).removeClass("delbg").addClass("addbg");
            });

            $(".new_city li").click(function () {
                $(this).remove();
                var cityKid2 = $("#ruleToCity").val();
                var dataStr = cityKid2.split(",");
                for (i = 0 ; i < dataStr.length; i++) {
                    if (dataStr[i] == $(this).val()) {
                        dataStr.baoremove(i);
                    }
                };
                $("#ruleToCity").val(dataStr);
            });
            $(".appear_city").fadeOut();

            var cityArr = "";
            var cityKid = $("#ruleToCity").val();
            $(".new_city").find("li[class='addbg']").each(function () {
                cityArr += $(this).attr("value");
                if (cityKid != null) {
                    cityArr += ",";
                }
                $("#ruleToCity").val(cityArr);
            });
        }

        $(function () {
            f_GetProductCategoryList();
            f_GetCityList();

            var kid = GetUrlParam("kid");
            if (kid > 0) {
                $("#kid").val(kid);
                $("#EditTitle").html("编辑商品");
                $(".Cancel").hide();
                f_GetProduct();
                //$(".Cancel").attr("disabled", true);

            } else {
                $("input[name='isSelect'][value=0]").attr("checked", true);
                $("input[name='isSelect'][value=0]").parent().addClass("checked");
            }
        });
        function f_GetCityList() {
            var data = kk.api.get("/System/GetCityList", function (data) {
                $("#F_CityKid").empty();
                $.each(data, function (i, obj) {
                    $("#F_CityKid").append("<option value='" + obj.F_CityKid + "'>" + obj.F_CityName + "</option>");
                });
            });

        }
        //获取商品详细
        function f_GetProduct() {
            $kk.api.get("/PointProduct/Get", {
                Kid: GetUrlParam("kid")
            }, function (res) {
                $("#imgBuilding").attr("src", res.F_PicUrl);
                $("#imgBuilding2").attr("src", res.T_ProductPic[0].F_PicUrl);
                $("#picUrl").val(res.F_PicUrl);
                $("#picUrl2").val(res.T_ProductPic[0].F_PicUrl);
                $("#Kid").val(res.Kid);
                $("#productName").val(res.F_ProductName);
                $("#pointNum").val(res.T_ExchangeRule.F_PointNum);
                $("#sort").val(res.F_Sort);
                $("#description").val(res.F_Description);
                $("#beginTime").val(res.T_ExchangeRule.F_BeginTime);
                $("#endTime").val(res.T_ExchangeRule.F_EndTime);
                $("input[name='isSelect'][value=" + res.T_ExchangeRule.F_Status + "]").attr("checked", true);
                $("input[name='isSelect'][value=" + res.T_ExchangeRule.F_Status + "]").parent().addClass("checked");
                $("#status").val(res.T_ExchangeRule.F_Status);
                $("#source").val(res.F_Source);
                if (res.T_ExchangeRule.F_Status == 0) {
                    $("#source").parents("tr").show();
                    $("#source").attr("validatetype", "*notempty");
                } else {
                    $("#source").parents("tr").hide();
                }
                $("#F_CateogryKid").val(res.F_CategoryKid)
                $("#categoryKid").val(res.F_CategoryKid);
                $("#productPrice").val(res.F_ProductPrice);
                $("#stockNum").val(res.F_StockNum);
                $("#inventoryNum").val(res.F_InventoryNum);
                $("#userExchangeNum").val(res.T_ExchangeRule.F_UserExchangeNum);
                $("#exchangeType").val(res.T_ExchangeRule.F_ExchangeType);
                if (res.T_ExchangeRule.F_ExchangeType) {
                    $(".sex_2").addClass("on");
                    $(".sex_1").removeClass("on");
                } else {
                    $(".sex_1").addClass("on");
                    $(".sex_2").removeClass("on");
                }
                //开启兑换限制
                $("#isExchange").val(res.T_ExchangeRule.F_IsExchange);
                $("#isMeskill").val(res.T_ExchangeRule.F_IsMeskill);
                $("#ruleKid").val(res.T_ExchangeRule.Kid);

                if (res.T_ExchangeRule.F_IsExchange) {
                    $("#F_CityKid").parents("tr").show();

                    $("#exchangeNum").parents("tr").show();
                    $("#beginHour").parents("tr").show();
                    $("#isMeskill").parents("tr").show();
                    $("#F_IsExchange").find("div").removeClass("switch-off").addClass("switch-on");

                    $("#exchangeNum").val(res.T_ExchangeRule.F_ExchangeNum);
                    $("#beginHour").val(res.T_ExchangeRule.F_ExchangeBeginTime.split(':')[0]);
                    $("#beginMinute").val(res.T_ExchangeRule.F_ExchangeBeginTime.split(':')[1]);
                    $("#endHour").val(res.T_ExchangeRule.F_ExchangeEndTime.split(':')[0]);
                    $("#endMinute").val(res.T_ExchangeRule.F_ExchangeEndTime.split(':')[1]);
                }
                if (res.T_ExchangeRule.F_IsMeskill) {
                    $("#F_IsMeskill").find("div").removeClass("switch-off").addClass("switch-on");
                }
                if (res.T_ExchangeRule.T_RuleToCity.length > 0) {
                    $("#F_CityKid").val(res.T_ExchangeRule.T_RuleToCity[0].F_CityKid);
                    $("#ruleToCity").val(res.T_ExchangeRule.T_RuleToCity[0].F_CityKid);
                }
            });
        }
        ////根据图片路径删除图片及清空对应的隐藏域
        function DeleteFileByUrl() {
            $("#imgBuilding").attr({ 'src': 'images/build_pics.jpg' });
            $("#picUrl").val('');
            //var url = $("#F_Logo").val();

            //$.post("/UpLoad/DeleteFileByImgUrl", { imgUrl: url }, function (result) {
            //    $.msgAlert(result, function (jsobj) {
            //        $('#imgBuilding').attr('src', "/Content/images/build_pics.jpg");
            //        $("#F_Logo").val("");
            //    });
            //});
        }

        function DeleteFileByUrl2() {
            $("#imgBuilding2").attr({ 'src': 'images/build_pics.jpg' });
            $("#picUrl2").val('');
        }
        //kk.api.add("a", "http://192.168.1.85:1060");
        //获取商品分类
        function f_GetProductCategoryList() {
            var data = kk.api.get("/ProductsCategory/GetList");
            //alert(JSON.stringify(data))
            $.each(data, function (i, obj) {
                $("#F_CateogryKid").append("<option value='" + obj.Kid + "'>" + obj.F_CategoryName + "</option>");
            });
        }

        $('#F_CateogryKid').change(function () {
            var CateogryKid = $(this).children('option:selected').val();
            $("#categoryKid").val(CateogryKid);
        });


        //提交保存及验证
        $(".inpall").blur(function () {
            validate($(this));
        })
        $(document).ready(function () {
            validateInit("");
        });

        //是否开启
        $('#F_IsExchange').on('switch-change', function (e, data) {
            if (!data.value) {
                $("#exchangeNum").parents("tr").hide();
                $("#beginHour").parents("tr").hide();
                $("#exchangeNum").val("");

                $("#beginHour").val("");
                $("#beginMinute").val("");

                $("#beginHour").val("");
                $("#endHour").val("");

                $("#isMeskill").parents("tr").hide();
                $("#isMeskill").val("0");

                $("#isExchange").val("0");

                $("#F_CityKid").parents("tr").hide();


            } else {
                $("#exchangeNum").parents("tr").show();
                $("#beginHour").parents("tr").show();
                $("#exchangeNum").val("0");


                $("#beginHour").val("8");
                $("#beginMinute").val("00");

                $("#endHour").val("18");
                $("#endMinute").val("00");

                $("#isMeskill").parents("tr").show();
                $("#isMeskill").val("0");

                $("#isExchange").val("1");

                $("#F_CityKid").parents("tr").show();

            }
        });

        $('#F_IsMeskill').on('switch-change', function (e, data) {
            value = data.value;
            if (value == false) {
                $("#isMeskill").val("0");
            } else {
                $("#isMeskill").val("1");
            }
        });


        //立即上架
        function f_ImmediatelyOn() {
            //商品分类判断
            if ($("#categoryKid").val() == null || $("#categoryKid").val() == 0 || $("#categoryKid").val() == "--商品分类--") {
                $kk.popup("请选择商品分类", "err", 1000);
                return;
            }
            //表单验证
            if (!validate("#form1 input[validateType]")) {
                return;
            }
            //时间判断
            if ($("#beginTime").val() == null || $("#beginTime").val() == "" || $("#beginTime").val() == undefined || $("#endTime").val() == null || $("#endTime").val() == "" || $("#endTime").val() == undefined) {
                $kk.popup("请选择兑换时期", "err", 1000); return;
            }

            f_SubmitSave();
            kk.api.post("/PointProduct/Save?typeId=1", $("#form1 :input[value],textarea").serializeArray(), function (res) {
                //alert(JSON.stringify(res));
                $kk.popup("成功上架", "success", 1500);
                setTimeout(function () { f_Back() }, 1000);
            });

        }
        //加入仓库
        function f_AddWarehouse() {
            if ($("#categoryKid").val() == null || $("#categoryKid").val() == 0 || $("#categoryKid").val() == "--商品分类--") {
                $kk.popup("请选择商品分类", "err", 1000);
                return;
            }
            //表单验证
            if (!validate("#form1 input[validateType]")) {
                return;
            }
            if ($("#beginTime").val() == null || $("#beginTime").val() == "" || $("#beginTime").val() == undefined || $("#endTime").val() == null || $("#endTime").val() == "" || $("#endTime").val() == undefined) {
                $kk.popup("请选择兑换时期", "err", 1000); return;
            }
            if (!f_SubmitSave()) {
                return;
            }
            kk.api.post("/PointProduct/Save?typeId=0", $("#form1 :input[value],textarea").serializeArray(), function (res) {
                //alert(JSON.stringify(res));
                $kk.popup("成功入库", "success", 1500);
                setTimeout(function () { f_Back() }, 1000);
            });
        }
        function f_Back() {
            self.location = document.referrer;
        }

        function f_SubmitSave() {
            var isTrue = true;

            if ($("#isExchange").val() == "1") {
                if ($("input[name='isSelect']").eq(0).prop("checked")) {
                    $("#status").val("0");
                } else {
                    $("status").val("1");
                }

                //if ($("#F_CityKid").val() == "")
                //{
                //    return $kk.alert("请选择城市", "提示");
                //}

                //时间判断
                var bHour = $("#beginHour").val();
                var eHour = $("#endHour").val();
                function isHour(num) {
                    if (!isNaN(num) && num >= 24 && num >= 0) {
                        $kk.popup("请重新输入有效的两位小时数(如15)", "err", 3000); return;
                        return isTrue = false;
                    }
                }
                isHour(bHour);
                isHour(eHour);

                var bMinute = $("#beginMinute").val();
                var eMinute = $("#endMinute").val();
                function isMinute(num) {
                    if (!isNaN(num) && num >= 60 && num >= 0) {
                        $kk.popup("请重新输入有效的两位小时数(如15)", "err", 3000); return;
                        return isTrue = false;
                    }
                }
                isMinute(bMinute);
                isMinute(eMinute);
                if (Number(bHour) >Number(eHour)) {
                    $kk.popup("每日限兑时间 开始时间不允许大于结束时间", "err", 3000); return;
                    return isTrue = false;
                }
                if ((Number(bHour) == Number(eHour)) && (Number(bMinute) > Number(eMinute))) {
                    $kk.popup("每日限兑时间 开始时间不允许大于结束时间", "err", 3000); return;
                    return isTrue = false;
                }
                $("#exchangeBeginTime").val(bHour + ":" + bMinute);
                $("#exchangeEndTime").val(eHour + ":" + eMinute);
            } else {
                $("#exchangeNum").val("0");
            }
            return isTrue;
        }

        function IsDouble(obj) {
            obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/^\./g, "");  //验证第一个字符是数字而不是.
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        }
    </script>
    <script type="text/javascript">
        function SexSelect1() {
            $(".sex_1").addClass("on");
            $(".sex_2").removeClass("on");
            $("#exchangeType").val(0);
            return false;

        }
        function SexSelect2() {
            $(".sex_2").addClass("on");
            $(".sex_1").removeClass("on");
            $("#exchangeType").val(1);
            return false;
        }
    </script>
</body>
</html>
